/* 
 * File:   NuevaCampania.cpp
 * Author: agu
 * 
 * Created on 6 de junio de 2014, 17:49
 */

#include "NuevaCampania.h"
#include <iostream>

NuevaCampania::NuevaCampania() {
    this->builder = Gtk::Builder::create();
    try {
        this->builder->add_from_file("nuevaCampania.glade");
    } catch (const Glib::FileError& ex) {
        std::cout << "FileError: " << ex.what() << std::endl;

    } catch (const Glib::MarkupError& ex) {
        std::cout << "MarkupError: " << ex.what() << std::endl;

    } catch (const Gtk::BuilderError& ex) {
        std::cout << "BuilderError: " << ex.what() << std::endl;

    }
    this->loadWidgets();
    this->connectWidgets();

}

void NuevaCampania::loadWidgets() {
    this->builder->get_widget("windowsNewCampain", this->window);
    this->builder->get_widget("buttonLevels", this->buttonLevels);
    this->builder->get_widget("buttonBack", this->buttonBack);
    this->builder->get_widget("buttonSave", this->buttonSave);
    this->builder->get_widget("entryName", this->entryName);
    this->builder->get_widget("comboImage", this->comboImage);
    this->builder->get_widget("comboDif", this->comboDif);
    this->builder->get_widget("spinTotalPlayers", this->spinTotalPlayers);
    this->builder->get_widget("spinTotalLevels", this->spinTotalLevels);
    this->builder->get_widget("message", this->message);
    this->builder->get_widget("buttonOk", this->buttonOk);
    this->builder->get_widget("buttonCancel", this->buttonCancel);
}

void NuevaCampania::connectWidgets() {
    this->window->signal_hide().connect(sigc::mem_fun(this, &NuevaCampania::close));
    this->buttonBack->signal_clicked().connect(sigc::mem_fun(this, &NuevaCampania::back));
    this->buttonLevels->signal_clicked().connect(sigc::mem_fun(this, &NuevaCampania::levelsList));
    this->buttonSave->signal_clicked().connect(sigc::mem_fun(this, &NuevaCampania::save));
    this->buttonOk->signal_clicked().connect(sigc::mem_fun(this, &NuevaCampania::saveExit));
    this->buttonCancel->signal_clicked().connect(sigc::mem_fun(this, &NuevaCampania::cancel));

}

NuevaCampania::~NuevaCampania() {
    delete this->window;
}

void NuevaCampania::run() {
    this->window->show();
}

void NuevaCampania::close() {
    this->window->close();
}

void NuevaCampania::back() {
    this->close();
}

void NuevaCampania::levelsList() {
    this->window->set_visible(false);
    this->levels.setWindowsBack(this->window);
    this->levels.run();
}

void NuevaCampania::save() {
    this->message->show();
}

void NuevaCampania::cancel() {
    this->message->hide();
}

void NuevaCampania::saveExit() {
    std::cout<<"Guardar y salir"<<std::endl;
}